package com.wutao.panzh.index.content.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.panzh.UtilEntity.ResultVO;
import com.panzh.entity.InformationItem;
import com.panzh.entity.index.IndexInformationItem;
import com.wutao.panzh.service.InforMationItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 为了避免重写，我们就直接用现成的InformationService进行处理了！
 */
@Controller
public class IndexInformationHandler {

    @Reference
    private InforMationItemService inforMationItemService;


    /**
     * 咱们默认还是要使用一个分页的东东的。
     * @return
     */
    @ResponseBody
    @RequestMapping("/get/all/index/information")
    public ResultVO getAllIndexInformation(@RequestParam(value="pageNo",defaultValue="1") Integer pageNo){
        PageInfo<IndexInformationItem> informationItemPageInfo = inforMationItemService.getAllIndexInformation(pageNo);
        return new ResultVO<PageInfo<IndexInformationItem>>(ResultVO.SUCCESS,ResultVO.NO_MSG ,informationItemPageInfo);
    }

//    a href='show_indexInformation_details?id = "+itemId+"'
    @RequestMapping("show_indexInformation_details")
    public String getShowIndexInformationDetails(@RequestParam("itemId") Integer itemId, Model model){
        //转来转去，我是真的吧自己弄烦了。
        InformationItem informationItem = inforMationItemService.getInformationItemById(String.valueOf(itemId));
        model.addAttribute("informationItem",informationItem);
        return "InformationDetails";
    }


}
